package com.baizhi.controller;

import com.baizhi.Depart;
import com.baizhi.service.DepartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@RestController
public class DepartController {
    @Autowired
    private DepartService ds;
    @GetMapping("/departs")
    public List<Depart> selectAll(){
        List<Depart> departs = ds.selectAll();
        return departs;
    }
    @PostMapping("/employees/upload")
    public Map<String,String> upload(MultipartFile file){
        final String newFile=UUID.randomUUID()+file.getOriginalFilename();
        File files=new File("e:/file/"+newFile);
        try {
            file.transferTo(files);//把内存图片写入磁盘中用transferTo方法
        } catch (IOException e) {
            e.printStackTrace();
        }
        return new HashMap<String, String>(){{
            put("fileName",newFile);
        }};
    }
}
